MySQL - Alter Command
The ALTER command is used to modify the existing table.
It involves adding,removing,modifying,creating,dropping,renaming,changing the engine,changing the collation of table or some columns.
SYNTAX :
ALTER TABLE table_name
ADD new_column_name column_definition
[ FIRST | AFTER column_name ];
Lets consider a table and check how alter command is performing :
ID | Name | Address | Company | Salary |
---|---|---|---|---|
1 | Nihari | Habsiguda | DELL | 25000 |
2 | Swara | Madhapur | HCL | 35000 |
3 | Lara | SR nagar | XIUS | 54000 |
4 | Kiara | KPHB | 64000 | |
5 | Harshad | Gachibowli | HP | 48000 |
ALTER TABLE employeerecord
ADD Gender varchar(55) NOT NULL
AFTER Salary;
Result will be displayed as follows:
ID | Name | Address | Company | Salary | Gender |
---|---|---|---|---|---|
1 | Nihari | Habsiguda | DELL | 25000 | - |
ALTER TABLE employeerecord DROP Column Gender;
Result will be displayed as follows:
ID | Name | Address | Company | Salary |
---|---|---|---|---|
1 | Nihari | Habsiguda | DELL | 25000 |
ALTER TABLE employeerecord
CHANGE COLUMN Salary Compensation
Int(55) NOT NULL;
ID | Name | Address | Company | Compensation |
---|---|---|---|---|
1 | Nihari | Habsiguda | DELL | 25000 |
MySQL - Grant_ Revoke Privilege
posted on 2019-11-26 23:15:04 - mysql Tutorials